<?php
require('SAM/php_sam.php');

define("SAM_HOST" , "SAM_HOST");
define("SAM_PORT" , "SAM_PORT");
define("SAM_MQTT_QOS" ,"SAM_MQTT_QOS" );
//create a new connection object
$conn = new SAMConnection();

//start initialise the connection
$conn->connect(SAM_MQTT, array( SAM_HOST => "test.mosquitto.org",
                                 SAM_PORT => 1883));

//while the connection exists
$i=0;
       while($conn)
       {
            //get the cpu usage using a shell command
           // $cmd = "cat /proc/loadavg";
           // $rawCpu=shell_exec($cmd);
           // $result=preg_match("/^\d+.\d+/", $rawCpu, $cpu);
            //if successful then send message
            // if(1)
                //{
                //create a new MQTT message with the output of the shell command as the body
				$time=time();
                $msgCpu = new SAMMessage("6,1,".$time);

                //send the message on the topic cpu
                $conn->send('topic://cpupc-asitha', $msgCpu);

                // print sent to the terminal
                echo "sent".$conn->error;

                //wait for a minute
               sleep(3);
			//}
			//$i++;
        }

?>